package com.bw.gmall.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.bw.gmall.bean.ResultBean;
import com.bw.gmall.domain.KeyWord;
import com.bw.gmall.service.IKeyWordService;
import com.bw.gmall.util.FastjsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/gmall/api")
public class KeyWordController {

    @Autowired
    private IKeyWordService keyWordService;

    @RequestMapping("/getKeyWord")
    public String getKeyWord(@RequestParam(value = "date", defaultValue = "0") Integer date){
        List<KeyWord> keyWord = keyWordService.getKeyWord(date);
        JSONArray array =  FastjsonUtils.toJSONArray(keyWord);
        ResultBean resultBean = new ResultBean();
        resultBean.data = array;
        return JSON.toJSONString(resultBean);
    }
}
